using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Weapons.Components.ComponentData;

namespace Light
{
    [CreateAssetMenu(fileName = "newWeaponData", menuName = "Data/Weapon Data/Basic Weapon Data", order = 0)]
    public class WeaponDataSO : ScriptableObject
    {
        [field: SerializeField] public RuntimeAnimatorController AnimatorController { get; private set; }

        [field: SerializeField] public int NumOfAttacks { get; private set; }

        //Unity�����л�����Ҫ�µ㹦��
        [field: SerializeReference] public List<ComponentData> ComponentDatas { get; private set; }

        public T GetData<T>()
        {
            return ComponentDatas.OfType<T>().FirstOrDefault();
        }

        public void AddData(ComponentData data)
        {
            if (ComponentDatas.FirstOrDefault(t => t.GetType() == data.GetType()) != null)
            {
                Debug.LogWarning("�������������ظ����ݣ�");
                return;
            } //learn point�� ȷ�����������û���ظ� ���ص�ѧϰһ����������ʽ�����ʹ��

            ComponentDatas.Add(data);
        }

        public List<Type> GetAllDependencies()
        {
            //return ComponentDataSelect(component => component.).toList(); �ƺ������˼���
            return ComponentDatas.Select(component => component.ComponentDependecny).ToList();
        }

        //marker��ѧϰ��
        [ContextMenu("Add Sprite Data")]
        private void AddSpriteData()
        {
            ComponentDatas.Add(new WeaponSpriteData());
        }

        [ContextMenu("Add Movement Data")]
        private void AddMovementData()
        {
            ComponentDatas.Add(new MovementData());
        }
    }
}